<!DOCTYPE html>
<html lang="en-US">
  <head>
    <title>Web Chat: Full-featured bundle with ES5 polyfills and Direct Line Speech channel</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <!--
      This CDN points to the latest official release of Web Chat. If you need to test against Web Chat's latest bits, please refer to using Web Chat's latest bits:
      https://github.com/microsoft/BotFramework-WebChat#how-to-test-with-web-chats-latest-bits
    -->
    <script
      crossorigin="anonymous"
      src="https://cdn.botframework.com/botframework-webchat/latest/webchat-es5.js"
    ></script>
    <style>
      html,
      body {
        height: 100%;
      }

      body {
        margin: 0;
      }

      #webchat {
        height: 100%;
        width: 100%;
      }
    </style>
  </head>
  <body>
    <div id="webchat" role="main"></div>
    <script>
      // In this demo, we are using Direct Line token from MockBot.
      // To talk to your bot, you should use the token exchanged using your Direct Line secret.
      // You should never put the Direct Line secret in the browser or client app.
      // https://docs.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-authentication

      // This code is modified to run in a browser that does not have async and Promise support
      const fetchCredentials = function () {
        return window
          .fetch('https://webchat-mockbot-streaming.azurewebsites.net/speechservices/token', {
            method: 'POST'
          })
          .then(function (res) {
            return res.json();
          })
          .then(function (json) {
            return {
              authorizationToken: json.token,
              region: json.region
            };
          });
      };

      window.WebChat.createDirectLineSpeechAdapters({ fetchCredentials: fetchCredentials }).then(function (adapters) {
        window.WebChat.renderWebChat(Object.assign({}, adapters), document.getElementById('webchat'));

        document.querySelector('#webchat > *').focus();
      });
    </script>
  </body>
</html>
